﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entities.IRepository;
using DAL;
using Entities;

namespace QuanLyBilliards_Coffee
{
    public partial class FormChiTietHoaDon : Form
    {
        public FormChiTietHoaDon()
        {
            InitializeComponent();
        }

        private void FormChiTietHoaDon_Load(object sender, EventArgs e)
        {
            lvDanhSachMatHang.Items.Clear();
            txtMaHD.Text = Form1.MaHD;
            IHoaDonRepository hd = new HoaDonRepository();
            HoaDon tkhd = hd.GetByMaHoaDon(txtMaHD.Text);
            txtNgayLap.Text = tkhd.NgayLap;
            if (tkhd.LoaiHD == true)
                txtLoaiHoaDon.Text = "Nhập";
            else
                txtLoaiHoaDon.Text = "Bán";
            txtNguoiLap.Text = tkhd.NguoiLap;
            IChiTietHoaDonRepository cthd = new ChiTietHoaDonRepository();
            IQueryable<ChiTietHoaDon> listcthd = cthd.getByMaHD(txtMaHD.Text);
            foreach (var item in listcthd)
            {
                IHangHoaRepository hh = new HangHoaRepository();
                HangHoa h = hh.GetByMaHangHoa(item.HangHoa);
                ListViewItem lvitem = new ListViewItem(txtMaHD.Text);
                lvitem.SubItems.Add(h.TenHH);
                lvitem.SubItems.Add(item.SoLuong.ToString());
                if (tkhd.LoaiHD == true)
                {
                    int thanhtien = h.GiaMua * item.SoLuong;
                    lvitem.SubItems.Add(thanhtien.ToString());
                }
                else
                {
                    int thanhtien = h.GiaBan * item.SoLuong;
                    lvitem.SubItems.Add(thanhtien.ToString());
                }
                lvDanhSachMatHang.Items.Add(lvitem);
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
